using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONConstant{
	#region 单例
	private static JSONConstant instance;
	public static JSONConstant getInstance(){
	if (instance == null)
		instance = new JSONConstant ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONConstant");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListKEY(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetKEY(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// Test开头的 是测试数据  并非常量
	/// </summary>
	public string GetKEY(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["KEY"].ToString();
		return  value;
	}
	/// <summary>
	/// Test开头的 是测试数据  并非常量 :From Index
	/// </summary>
	public string GetKEY(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetKEY(index.ToString());
			return  value;
		}
		value = json["KEY"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListINFO(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetINFO(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 
	/// </summary>
	public string GetINFO(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["INFO"].ToString();
		return  value;
	}
	/// <summary>
	///  :From Index
	/// </summary>
	public string GetINFO(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetINFO(index.ToString());
			return  value;
		}
		value = json["INFO"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListValue_String(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetValue_String(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 
	/// </summary>
	public string GetValue_String(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Value_String"].ToString();
		return  value;
	}
	/// <summary>
	///  :From Index
	/// </summary>
	public string GetValue_String(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetValue_String(index.ToString());
			return  value;
		}
		value = json["Value_String"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListValue_Int(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetValue_Int(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 
	/// </summary>
	public int GetValue_Int(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Value_Int"].AsInt;
		return  value;
	}
	/// <summary>
	///  :From Index
	/// </summary>
	public int GetValue_Int(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetValue_Int(index.ToString());
			return  value;
		}
		value = json["Value_Int"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListValue_Float(float target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetValue_Float(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 
	/// </summary>
	public float GetValue_Float(string key){
		JSONNode json = GetJSON (key);
		float  value;
		value = json["Value_Float"].AsFloat;
		return  value;
	}
	/// <summary>
	///  :From Index
	/// </summary>
	public float GetValue_Float(int index){
		float value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetValue_Float(index.ToString());
			return  value;
		}
		value = json["Value_Float"].AsFloat;
		return  value;
	}

	#endregion
}